package com.ruoyi.web.vo;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.utils.biz.CommonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description 航天发射任务大气模型评估-入参
 * @Author liuhl
 * @Date 2024/6/4
 **/
@Data
@ApiModel(value = "SpaceLaunchVo", description = "航天发射任务大气模型评估-入参")
public class SpaceLaunchVo {

    @ApiModelProperty("评估时间，yyyy-mm-dd")
    private String time;

    @ApiModelProperty("位置数组，每个元素都是a,b格式的经纬度")
    private List<String> locations;

    @NotNull(message = "评参模型不能为空")
    @Size(min = 2,message = "请选中两个评参模型")
    @ApiModelProperty("模型数组")
    private List<String> models;

    @ApiModelProperty("计算结果路径")
    private String txtPath;

    public String getLocations(){
        return this.locations.stream()
                .map(o -> o.replace(",", ":")) //将逗号修改成冒号
                .sorted()
                .collect(Collectors.joining(","));
    }

    public List<String> getLocationList(){
        return this.locations;
    }

    public String getModels(){
        return this.models.stream()
                .sorted()
                .collect(Collectors.joining(","));
    }

    public static void main(String[] args) {

        String txtPath = "C:\\Users\\HTHT\\Desktop\\fsdownload\\SpaceLaunch.txt.txt";
        String content = CommonUtil.readStrData(new File(txtPath), null);
        Map<String, JSONObject> contentMap = JSONUtil.toBean(content, Map.class);
        List<String> locationList = Stream.of("39.61,-67.88","27.85,-40.73").collect(Collectors.toList());

        Map<String,Object> resultMap = new HashMap<>();
        Map<String,Object> locationAndHeightMap = new HashMap<>();

        Map<String,Object> modelDataMap = (Map<String,Object>)contentMap.get("modelData");

        //1.观测值和参评模型模拟值分布结果图
        Map<String,Object> simuMap = new HashMap<>();
        locationList.forEach(location -> {
            Map<String,Object> modelDataAndHeightMap = (Map<String,Object>)modelDataMap.get(location + "_Simu");
            Object densityData = modelDataMap.get(location + "_Density");
            Object heightData = modelDataMap.get(location + "_Height");
            modelDataAndHeightMap.put("Density",densityData);
            modelDataAndHeightMap.put("Height",heightData);

            locationAndHeightMap.put(location, heightData); //顺便记录下高度数组，后面要用
            simuMap.put(location, modelDataAndHeightMap);
        });
        resultMap.put("simu", simuMap);
    }

}
